﻿using System;
using System.Runtime.InteropServices;

namespace wdwp.Desktop.widgetLib.Utils
{
    /// <summary>
    /// Native Win32 API를 이용하기 위한 API 선언의 모음
    /// </summary>
    public class NativeWin32
    {
        /// <summary>
        /// IPC
        /// </summary>
        public const int WM_COPYDATA                     = 0x004A;

        /// <summary>
        /// IPC
        /// </summary>
        public const int WM_USER                         = 0x0400;
        
        
        /// <summary>
        /// for Mouse movement
        /// </summary>
        public const int WM_MOUSEMOVE                    = 0x0200;

        /// <summary>
        /// for Mouse movement
        /// </summary>
        public const int WM_LBUTTONDOWN                  = 0x0201;

        /// <summary>
        /// for Mouse movement
        /// </summary>
        public const int WM_LBUTTONUP                    = 0x0202;

        /// <summary>
        /// for Mouse movement
        /// </summary>
        public const int WM_LBUTTONDBLCLK                = 0x0203;

        /// <summary>
        /// for Mouse movement
        /// </summary>
        public const int WM_RBUTTONDOWN                  = 0x0204;

        /// <summary>
        /// for Mouse movement
        /// </summary>
        public const int WM_RBUTTONUP                    = 0x0205;

        /// <summary>
        /// for Mouse movement
        /// </summary>
        public const int WM_RBUTTONDBLCLK                = 0x0206;

        /// <summary>
        /// for Mouse movement
        /// </summary>
        public const int WM_NCLBUTTONDOWN                = 0x00A1;

        /// <summary>
        /// 창 배치
        /// </summary>
        public static readonly  IntPtr HWND_TOPMOST = new IntPtr(-1);

        /// <summary>
        /// 창 배치
        /// </summary>
        public static readonly  IntPtr HWND_NOTOPMOST = new IntPtr(-2);

        /// <summary>
        /// 창 배치
        /// </summary>
        public static readonly  IntPtr HWND_TOP = new IntPtr(0);

        /// <summary>
        /// 창 배치
        /// </summary>
        public static readonly  IntPtr HWND_BOTTOM = new IntPtr(1);

        /// <summary>
        /// 창 사이즈
        /// </summary>
        public const UInt32 SWP_NOSIZE = 0x0001;

        /// <summary>
        /// 창 사이즈
        /// </summary>
        public const UInt32 SWP_NOMOVE = 0x0002;
        

        /// <summary>
        /// Win32 SendMessage API
        /// </summary>
        /// <param name="hWnd">Window Handle</param>
        /// <param name="msg">Message</param>
        /// <param name="wParam">wParam</param>
        /// <param name="lParam">lParam</param>
        /// <returns>suceess = 1 , fails = other</returns>
        [DllImport("User32.dll", CharSet = CharSet.Auto)]
        public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, object lParam);

        /// <summary>
        /// 화면의 마우스 캡쳐를 해제
        /// </summary>
        /// <returns></returns>
        [DllImport("User32.dll", CharSet = CharSet.Auto)]
        public static extern int ReleaseCapture();
        
        /// <summary>
        /// 현재 창의 메세지 루프에서 메세지를 얻어옴
        /// </summary>
        /// <param name="lpMsg">메세지를 받을 포인터</param>
        /// <param name="hWnd">창의 핸들</param>
        /// <param name="wMsgFilterMin">필터 최소치</param>
        /// <param name="wMsgFilterMax">필터 최대치</param>
        /// <returns></returns>
        [DllImport("User32.dll", CharSet = CharSet.Auto)]
        public static extern int GetMessage(int lpMsg, int hWnd, int wMsgFilterMin, int wMsgFilterMax);
        
        /// <summary>
        /// 창의 크기와 형태를 지정 
        /// </summary>
        /// <param name="hWnd">창의 핸들</param>
        /// <param name="hWndInsertAfter">창의 부모창의 핸들러</param>
        /// <param name="X">X좌표</param>
        /// <param name="Y">Y좌표</param>
        /// <param name="cX">너비</param>
        /// <param name="cY">높이</param>
        /// <param name="uFlags">마스킹 플래그, API문서 참조</param>
        /// <returns></returns>
        [DllImport("User32.dll", CharSet = CharSet.Auto)]
        public static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cX, int cY, uint uFlags);
        
    }

}

